/**
 * @ClassName Offer55
 * @Description 剑指 Offer 55 - I. 二叉树的深度
 * @Author clockTown
 * @Date 2021/8/30 21:52
 * @Version 1.0
 */
class Offer55 {
}

/**
 * DFS
 */
class Offer55V0 {
    private int depth;
    public int maxDepth(TreeNode root) {
        dfs(root, 0);
        return depth;
    }

    private void dfs(TreeNode root, int level){
        if (root == null){
            depth = Math.max(depth, level);
            return;
        }
        dfs(root.left, level + 1);
        dfs(root.right, level + 1);
    }
}


class Offer55V1 {
    private int depth;
    public int maxDepth(TreeNode root) {
        dfs(root, 0);
        return depth;
    }

    private void dfs(TreeNode root, int level){
        if (root == null){
            depth = Math.max(depth, level);
            return;
        }
        dfs(root.left, level + 1);
        dfs(root.right, level + 1);
    }
}